package networkLoader;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;

import common.Device;
import common.Rule;

public class VDevice {
    private String name;
    private ArrayList<Rule> initialRules = new ArrayList<>();
    private HashMap<String, VPort> nameToPort = new HashMap<>();

    public VDevice(String name) {
        this.name = name;
        this.addPort("default");
    }

    public String getName() {
        return name;
    }

    public VPort addPort(String name) {
        VPort port = new VPort(name);
        port.setVDevice(this);
        this.nameToPort.put(name, port);
        return port;
    }

    public VPort getPort(String name) {
        nameToPort.putIfAbsent(name, new VPort(name, this));
        return this.nameToPort.get(name);
    }

    public Collection<VPort> getPorts() {
        return this.nameToPort.values();
    }
    
    public void addInitialRule(Rule rule) {
        this.initialRules.add(rule);
    }

    public ArrayList<Rule> getInitialRules() {
        return initialRules;
    }
}
